<template>
    <div class="my">
        <header>
            <img src="../assets/yx.png" alt="">
            <van-search v-model="value" placeholder="账号" left-icon="manager" />
            <van-password-input :value="pass" :focused="showKeyboard" @focus="showKeyboard = true" />
            <van-number-keyboard v-model="pass" :show="showKeyboard" @blur="showKeyboard = false" />
            <van-button type="warning" @click="submit()">登录</van-button>
        </header>
    </div>
</template>

<script>
    import { postLogin } from "../api/api"
    export default {
        name: 'YxMypage',
        data() {
            return {
                user: '',
                pass: "",
                value: "",
                showKeyboard: true,
            };
        },

        mounted() {

        },

        methods: {
            submit() {
                //账号
                let object = ({
                    user: this.value,
                    pass: this.pass
                })
                let username = object['user'];
                let pwd = object['pass'];
                console.log(typeof username,typeof pwd)
                postLogin({
                    username,
                    pwd
                }).then((res) => {
                    if(res.errno ===0){
                     
                       localStorage.setItem('token',res.data.token);
                       localStorage.setItem('userInfo',JSON.stringify(res.data.userInfo))
                         setTimeout(() => {
                            this.$toast('登录成功');
                            this.$router.push({path:'Mylogin'})
                        }, 1000);
                      
                       
                    }
                })
            }
        },
    };
</script>

<style lang="scss" scoped>
    .my {
        position: fixed;
        width: 7.5rem;
        height: 13rem;
        background-color: #F2F5F4;
        text-align: center;

        header {
            margin-top: 1.5rem;
            /* display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center; */
        }

        img {
            width: 2.68rem;
            height: 0.9rem;
            margin-bottom: .5rem;
        }

        .van-button {
            width: 1.8rem;
            margin-top: .4rem;
            height: 1rem;
            border-radius: .4rem;
            background-color: #DD1A21;
            color: #ddd;
        }

        /deep/ .van-search {
            background-color: #F2F5F4;
        }
    }

</style>
